<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> 后台管理开发框架</title>
<link href="/favicon.ico" rel="icon">
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="/static/admin/layui/css/layui.css" rel="stylesheet" type="text/css" />
<link href="/static/admin/css/style.css" rel="stylesheet" type="text/css" />
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- 重定位style -->
<style>
    .fileManager li:hover {
        background-color: #f7f7f7;
        cursor: pointer;
    }   
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div id="fileManager" lay-filter="fileManager" ></div>
    </div>
</div>

<script src="/static/admin/layui/layui.js?v=1.0.0"></script>
<script src="/static/admin/js/common.js?v=1.0.0"></script>
<script>
    layui.use(['admin','table','fileManager','upload'], function () {
        var admin = layui.admin;
        var jquery = layui.jquery;
        var upload = layui.upload;
        var fileManager = layui.fileManager;
        /*
            后期会重写这部分源码！界面有点太简单了！
            不过开源作者也不易，支持下，毕竟用人的组件！
            暂时就这样吧，要写的话，很多东西要全部进行重构！
        */
        fileManager.render({
            id: 'files'
            ,method:'post'
            ,btn_upload: true
            ,btn_create: true
            ,elem: '#fileManager'
            ,url: "{:url('/system.adminfile/index')}"
            ,parseData: function (res) {
                let _res = [];
                _res.code = 0;
                _res.data = res.images;
                _res.count = res.count
                return _res;
            }
            ,done: function (res,curr,count) {
            }
            ,page: {
                limit:30
            }
            ,where: {
                action: 'get_file_data'
            }
        });

        var upIns = upload.render({
            elem: '#uploadfile' //绑定元素
            ,url: "{:url('/upload/upload')}" //上传接口
            ,done:function(res, index, upload){
                if (res.code == 200) {
                    layui.iziToast.success({
                        message: res.msg,
                    });  
                    fileManager.reload('files');
                }
            }
        })

        fileManager.on('uploadfile(files)', function(obj){
            upIns();
        });

        //监听新建文件夹事件
        fileManager.on('new_dir(files)', function(obj){
            layui.iziToast.info({
                message:"暂未写接口！",
            });  
        });
    })
</script>
